// 内置模块 - react-app-rewired和customize-cra的配置代理写法
const { createProxyMiddleware } = require('http-proxy-middleware')

/**
 * 两种引入情况 ↑↑↑ ↓↓↓
 * 天坑: ↓↓↓↓↓↓↓ -- 这是不配置react-app-rewired和customize-cra的代理写法
 * const proxy = require('http-proxy-middleware') -- 不是引入这个
 * react-app-rewired2.x网址: https://www.cnblogs.com/zyl-Tara/p/10635033.html
 */

module.exports = function (app) {
  // 接口网址: https://cnodejs.org/api
  app.use('/cnode',
    createProxyMiddleware({
      target: 'https://cnodejs.org/api/v1',
      changeOrigin: true,
      pathRewrite: {
        "^/cnode": "/"
      }
    })
  )
  // sss
  app.use('/apiblog',
    createProxyMiddleware({
      target: 'http://localhost:3006',
      changeOrigin: true,
      // pathRewrite: {
      //   "^/tblog": ""
      // }
    })
  )
  app.use('/blog-avatar',
    createProxyMiddleware({
      target: 'http://localhost:3006',
      changeOrigin: true,
      // pathRewrite: {
      //   "^/tblog": ""
      // }
    })
  )
}
